//@ts-ignore

//@ts-ignore
import { escapemarkedunescape } from "./escapemarkedunescape";
import { rendercodeormath } from "./rendercodeormath";

export default async function compile_into_dom(
    stylecssrules: Set<string>,
    rawdata: string,
    mdurl: string
): Promise<ChildNode[]> {
    console.log([rawdata]);
    const path = mdurl;
    const mddata = await escapemarkedunescape(rawdata, { baseUrl: path });

    const tmpdoc = document.implementation.createHTMLDocument("");

    tmpdoc.body.innerHTML = mddata;
    const doccontainer = tmpdoc.body;
    const codeelements = Array.from(
        doccontainer.querySelectorAll("pre>code")
    ) as HTMLElement[];
    const preandcodeeles = Array.from(codeelements).map((code) => {
        return { code: code, pre: code.parentElement };
    });
    await rendercodeormath(stylecssrules, preandcodeeles /* , path */);
    return Array.from(tmpdoc.body.childNodes);
}
